package com.dolphin.common.component.var.enums;

import lombok.Getter;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

@Getter
@ToString
public enum TimeSliceUnitEnum {
    SS("秒", "SECOND", 1000L, 0),
    MIN("分", "MIN", 60 * 1000L, 1),
    HH("时", "HOUR", 60 * 60 * 1000L, 2),
    DAY("日", "DAY", 24 * 3600 * 1000L, 3),
    WEEK("周", "WEEK", 7 * 24 * 3600 * 1000L, 4),
    MONTH("月", "MONTH", 30 * 24 * 3600 * 1000L, 5)
    ;

    private String code;
    private String description;
    private Integer id;
    private long time;

    TimeSliceUnitEnum(String code, String description, long time, Integer id) {
        this.code = code;
        this.description = description;
        this.id = id;
        this.time = time;
    }

    public static TimeSliceUnitEnum formString(String timeSliceUnit){
        if(StringUtils.isEmpty(timeSliceUnit)){
            return null;
        }

        for(TimeSliceUnitEnum item : values()){
            if(item.name().equals(timeSliceUnit)){
                return item;
            }
        }

        throw new RuntimeException("Unsupported timeSliceUnit:" + timeSliceUnit);
    }
}
